@extends('layouts.admin')
@section('content')
	<div id="content-header">
		<h1>用户管理</h1>
		<div class="btn-group">
			<a class="btn btn-large tip-bottom" title="Manage Files"><i class="icon-file"></i></a>
			<a class="btn btn-large tip-bottom" title="Manage Users"><i class="icon-user"></i></a>
			<a class="btn btn-large tip-bottom" title="Manage Comments"><i class="icon-comment"></i><span class="label label-important">5</span></a>
			<a class="btn btn-large tip-bottom" title="Manage Orders"><i class="icon-shopping-cart"></i></a>
		</div>
	</div>
	<div id="breadcrumb">
				<a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i>用户列表</a>
				<a href="#" class="current">用户详情</a>
			</div>
	<div class="container-fluid">
				<div class="row-fluid">
					<div class="span12">
						<div class="widget-box">
							<div class="widget-title">
								<span class="icon" style="margin-top:-5px">
									<form id="sfrom">
										{{ csrf_field() }}
										<input type="text" name='search' id="search">
                       				 </form>
								</span>
								<span class="label label-info"><a href="{{url('admin/user/create')}}" style="color:white">添加用户</a></span>
							</div>
							<div class="widget-content">
								<span class="r">共有数据：<strong id="r">{{ $count}}</strong> 条</span>
								<table class="table table-bordered table-striped with-check">
									<thead>
										<tr>
											<th>排序</th>
											<th>ID</th>
											<th>用户名</th>
											<th>后台登陆权限</th>
											<th>角色</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody id="tb">
									@foreach($user as $u)
										<tr>
											<td style="line-height:50px"><input type="text" name="ord[]" value="{{$u->order}}" style="width:40px;text-align:center;line-height:50px;margin-bottom:0px" onchange="changeOrder(this,{{$u->id}})"></td>
											<td style="text-align:center;line-height:50px">{{$u->id}}</td>
											<td style="text-align:center;line-height:50px">{{$u->username}}</td>
											<td style="text-align:center;line-height:50px"><button class="btn btn-primary" id="btn{{$u->id}}" onclick="changesta(this,{{$u->id}})">{{$u->status==1 ? '开启':'关闭'}}</button></td>
											<td style="text-align:center;line-height:50px">{{$u->dname}}</td>
											<td style="text-align:center;line-height:50px"><button type="button" class="btn btn-success"><a href="{{url('admin/user/'.$u->id. '/edit?page='.$page)}}" style="color:white">修改</a></button> | <button type="button" class="btn btn-danger"><a href="javascript:" onclick="delArt({{$u->id}})" style="color:white">删除</a></button> | <button type="button" class="btn btn-danger"><a href="{{url('admin/riddle/'.$u->id)}}" style="color:white">添加角色</a></button></td>
										</tr>
										@endforeach
									</tbody>
									<tr>
										<td colspan="5">
									<div id="pagebox">
										<!-- 第一部分 -->
										<a href="javascript:void(0)" id="page1" onclick="page(1)">首页</a>
										<a href="javascript:void(0)" id="page2" onclick="page(<?php echo 1 ?>)">上一页</a>
										<a href="javascript:void(0)" id="page3" onclick="page(<?php echo 2 ?>)">下一页</a>
										<a href="javascript:void(0)" id="page4" onclick="page(<?php echo 1000000 ?>)">尾页</a><br />
									</div>
										</td><td>
									<div style="display: inline-block;margin-left: 10px"><sapn>第</sapn><strong id="ever">{{ $page }}</strong>/<sapn id="all">{{ $sums }}</sapn><span>共</span></div>
										</td>
									</tr>
								</table>


							</div>
						</div>

					</div>
				</div>
				<div class="row-fluid">
					<div id="footer" class="span12">
						2012 &copy; Unicorn Admin. Brought to you by <a href="https://wrapbootstrap.com/user/diablo9983">diablo9983</a>
					</div>
				</div>
			</div>
	<script type="text/javascript">
                function changeOrder(obj,id){
                    var order = $(obj).val();
                    $.post("{{url('admin/user/changeOrder')}}",{'_token':'{{csrf_token()}}','id':id,'order':order},function(data){
                       console.log(data);
                        if(data.status==0){
                            layer.alert(data.msg, {icon: 6});
                        }else{
                            layer.msg(data.msg, {icon: 5});
                        }
                    });
                }
                function changesta(obj,id){
                    $.post("{{url('admin/user/changeSta')}}",{'_token':'{{csrf_token()}}','id':id},function(data){
                        if(data.status==0){
                            layer.alert(data.msg, {icon: 6});
                             if ($('#btn'+id).html()=='开启') {
                             	$('#btn'+id).html('关闭');
                             }else{
                             	$('#btn'+id).html('开启');
                             }
                        }else{
                            layer.msg(data.msg, {icon: 5});
                        }
                    });
                }
                // 删除友情导航
                function delArt(id){
                    layer.confirm('您确定要删除？', {
                        btn: ['确定','取消'] //按钮
                    }, function(){
                        $.post("{{url('admin/user')}}/"+id,{'_method':'delete','_token':'{{csrf_token()}}'},function(data){
                            if(data.status==0){
                                location.href=location.href;
                                layer.msg(data.msg,{icon:6});
                            }else{
                                layer.msg(data.msg,{icon:5});
                            }
                        });
                    }, function(){
                    });
                }
                function page(page){
                    var value = $('#search').val();
                    $.ajax({
                        type:"get",
                        url:"{{ url('admin/user/show') }}",
                        dataType:'json',
                        data:{
                            'page':page,
                            'data':value
                        },
                        success:function(data){
								console.log(data);
                            var json = data;
                            if(json.msg == '1'){
                                console.log(json.data);
                                $('#tb').html(json.data);
		                       console.log(json);
                                $('#pagebox').html(json.page);
                                $('#r').html(json.count);
                                $('#ever').html(json.ever);
                                $('#all').html(json.all);
                            }else{
                                $('#tb').html(json.data);
                                $('#r').html(0);
                                $('#ever').html(0);
                                $('#all').html(0);
                            }
                        }
                    })
                }
                $("#search").bind("keyup change",function () {
                    //数据验证
                    //获取数据
                    var value = $('#search').val();

                    $.ajax({
                        type: 'post',
                        dataType: 'json',
//                        data: $('#sfrom').serialize(),
						data:{'data':value,'_token':'{{csrf_token()}}'},
                        url: '{{url('admin/user/show')}}',
                        success: function (data) {
                            console.log(data);
                            var obj = data;
                            if(obj.msg==1){
                                console.log(1111);
                                console.log( $('#tb').html(obj.data));
                                $('#pagebox').html(obj.page);
                                $('#r').html(obj.count);
                                $('#ever').html(obj.ever);
                                $('#all').html(obj.all);
                            }else {
                                $('#tb').html(obj.data);
                                console.log(2222);
//                        		$('#pagebox').html('');
                                $('#r').html(0);
                                $('#ever').html(1);
                                $('#all').html(0);
                            }
                        }
                    });
                })

			</script>
@endsection